﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Serious
{
    public static class Common
    {
        public static void Swap<T>(ref T primary, ref T other)
        {
            T temp = primary;
            primary = other;
            other = temp;
        }

        public static void Cycle<T>(T[] items, bool reverse=false)
        {
            if (items.Length == 0) return;

            T temp;
            if (!reverse)
            {
                temp = items[0];
                for (int k = 0; k < items.Length - 1; k++)
                {
                    items[k] = items[k + 1];
                }
                items[items.Length - 1] = temp;
            }
            else
            {
                temp = items[items.Length-1];
                for (int k = items.Length-1; k > 0; k--)
                {
                    items[k] = items[k-1];
                }
                items[0] = temp;
            }
        }
    }
}
